package com.nolon.flange.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.nolon.flange.model.Part

@Dao
interface PartDao {

    @Insert
    suspend fun insert(part: Part): Long

    @Insert
    suspend fun insertAll(parts: List<Part>)

    @Delete
    suspend fun delete(part: Part)

    @Update
    suspend fun update(part: Part)

    @Query("SELECT * FROM part_table WHERE id = :id")
    suspend fun getPart(id: Int): Part


    @Query("SELECT * FROM part_table WHERE project_id = :projectId")
    fun getAllByProjectId(projectId: Int): LiveData<List<Part>>

    @Query("DELETE  FROM part_table WHERE id = :id ")
    suspend fun deleteById(id: Int)

    @Query("DELETE  FROM part_table WHERE project_id = :projectId")
    suspend fun deleteAllByProjectId(projectId: Int)

    @Query("DELETE  FROM part_table WHERE project_id = :projectId")
    suspend fun deleteAllByProjectIdAndOrderId(projectId: Int)

}
